<template>
	<view>
		<view class="title "></view>

		<scroll-view scroll-y="true" class="scroll-Y" :style='{ height: scrollHeight }'>

			<view class="grid col-2 margin-xs">
				<view class="">
					<view class="bg-pannel  text-center margin-xs" hover-class="opcity" hover-stay-time="150"
						@tap="onScan()">
						<view class="padding-sm"></view>
						<view class="margin-lg"><text class="iconfont icon-scan4 text-sl "></text></view>
						<view class="margin-lg"><text class=" text-xl ">扫码</text></view>
					</view>
				</view>

				<view class=" ">
					<view class="bg-pannel  text-center margin-xs" hover-class="opcity" hover-stay-time="150"
						@tap="onTopo()">
						<view class="padding-sm"></view>
						<view class="margin-lg"><text class="iconfont icon-danganguanli text-sl "></text>
						</view>
						<view class="margin-lg"><text class=" text-xl ">档案维护</text></view>
					</view>
				</view>

				<!-- <view class=" ">
					<view class="bg-pannel  text-center margin-xs" hover-class="opcity" hover-stay-time="150" @tap="onSet()">
						<view class="padding-sm"></view>
						<view class="margin-lg"><text class="iconfont icon-yingjian text-sl text-grey"></text></view>
						<view class="margin-lg"><text class=" text-xl text-main-color">更换终端</text></view>
					</view>
				</view> -->

				<view class=" ">
					<view class="bg-pannel  text-center margin-xs" hover-class="opcity" hover-stay-time="150"
						@tap="onReplaceFeedNode()">
						<view class="padding-sm"></view>
						<view class="margin-lg"><text class="iconfont icon-siweiqi text-sl "></text></view>
						<view class="margin-lg"><text class=" text-xl ">更换饲喂器</text></view>
					</view>
				</view>



				<!-- <view class=" ">
					<view class="bg-pannel  text-center margin-xs" hover-class="opcity" hover-stay-time="150" @tap="onSet()">
						<view class="padding-sm"></view>
						<view class="margin-lg"><text class="iconfont icon-pig text-sl text-grey"></text></view>
						<view class="margin-lg"><text class=" text-xl text-main-color">猪只管理</text></view>
					</view>
				</view> -->

				<!-- <view class=" ">
					<view class="bg-pannel  text-center margin-xs" hover-class="opcity" hover-stay-time="150" @tap="onSet()">
						<view class="padding-sm"></view>
						<view class="margin-lg"><text class="iconfont icon-baoxiu1 text-sl text-grey"></text></view>
						<view class="margin-lg"><text class=" text-xl text-main-color">设备保修</text></view>
					</view>
				</view> -->
			</view>

			<view class="flex padding-left-xs padding-right-xs ">

			</view>

		</scroll-view>
	</view>


</template>
<script >
	//import { scan } from '@/uni_modules/hw-scankit'
	import * as api from 'common/api.js';

	import {
		API_HEAD
	} from '../../../common/api';
	export default {
		data() {
			return {
				scrollHeight: 0,
				farms: [],
				actions: [],
				node_replace_permission: false,
			}
		},
		onReady() {
			// 计算scroll-view高度
			uni.getSystemInfo({
				success: resu => {
					//console.info("窗口高度:", resu.windowHeight)
					const query = uni.createSelectorQuery()
					query.select('.title').boundingClientRect()
					query.exec(res => {

						//console.info("顶部下拉区域:", res[0])
						this.scrollHeight = resu.windowHeight - res[0].height - 10 + 'px';
						//console.log('剩余高度', this.scrollHeight);
					})
				}
			})
		},
		onShow: function() {
			console.info("show home")
		},
		created() {

		},
		onLoad() {
			console.info("load home")
		},
		onNavigationBarButtonTap(e) {

		},
		methods: {
			onSet() {
				uni.showToast({
					title: '您无权限操作',
					icon: 'none'
				})
			},
			onScan() {
				var that = this
				uni.scanCode({
					scanType: ['qrCode'],
					success: function (res) {
						console.log('条码类型：' + res.scanType)
						console.log('条码内容：' + res.result)
						
						var code = res.result
						var idx = code.indexOf('MXCSWQ_')
						if(idx<0)
						{
							idx = code.indexOf('MXCZLQ_')
						}
						if (idx >= 0) {
							var sn_arr = code.split("_")
							if (sn_arr.length != 2) {
								uni.showModal({
									title: "错误的条码",
									content: "请扫码设备屏幕/标签上正确的条码",
									showCancel: false,
									confirmText: "确定"
								})
							} else {
								var sn = sn_arr[1]
								//判断sn是否有权限
						
								uni.navigateTo({
									url: "/pages/feednode/feednode?sn=" + sn
								})
							}
						
						} else {
							uni.showModal({
								title: "错误的条码",
								content: "请扫码设备屏幕/标签上正确的条码",
								showCancel: false,
								confirmText: "确定"
							})
						}
					}
				});

				
			},
			onReplaceFeedNode() {
				//检查权限
				var that = this
				getApp().getActions("/Device/ReplaceFeedNode").then(function(res) {
					if (res.code >= 0) {
						console.info(res.data)
						that.actions = res.data
						var permission_ok = false
						for (var i = 0; i < that.actions.length; i++) {
							if (that.actions[i].action_id == 'view') {
								permission_ok = true
							}
						}

						if (permission_ok) {
							uni.navigateTo({
								url: "/pages/feed_node_replace/index"
							})
						} else {
							uni.showToast({
								title: '您无权限操作',
								icon: 'none'
							})
						}
					} else {
						uni.showToast({
							title: '系统异常，请联系管理员',
							icon: 'none'
						})
					}
				})
			},

			onTopo() {
				//检查权限
				var that = this
				getApp().getActions("/Topo/Tree").then(function(res) {
					if (res.code >= 0) {
						console.info(res.data)
						that.actions = res.data
						var permission_ok = false
						for (var i = 0; i < that.actions.length; i++) {
							if (that.actions[i].action_id == 'view') {
								permission_ok = true
							}
						}

						if (permission_ok) {
							uni.navigateTo({
								url: "/pages/topo/farm_list"
							})
						} else {
							uni.showToast({
								title: '您无权限操作',
								icon: 'none'
							})
						}
					} else {
						uni.showToast({
							title: '系统异常，请联系管理员',
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style>
	.bg-pannel {
		min-height: 300rpx;
		border-radius: 10rpx;
		/* opacity: 0.9; */
		/* background: url("https://www.hozenn.com/iot/img/house.png") 80% 50% / 40% no-repeat linear-gradient(to top, rgba(255, 255, 255, 0.95)); */
		/* background-image:linear-gradient(to top, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0)),url('https://www.hozenn.com/iot/img/house.png'); */
		/* background-repeat: no-repeat; */
		/* background-size: 20%; */
		/* background-position: 55% 50%; */
		background-color: rgba(200, 200, 200, 0.3);
		box-shadow: 0 4px 2px rgba(100, 100, 100, 0.3);
		/* background:  linear-gradient(135deg, #3c7cff 60%, #67d3ce 100%) !important; */
		/* opacity: 0.5; */
	}

	.opcity {
		opacity: 0.6;
	}

	.padding-xxs {
		padding: 2px;
	}

	.title {
		position: relative;
		font-weight: 700;
		font-size: 24px;
		line-height: 44px;
		text-align: center;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		padding: 5rpx;
		/* background-color: tra; */
	}

	.split {
		border-right: 2px solid #f5f3f330;
	}
</style>